package com.huwaiwai.spring.myioc;

import com.google.common.collect.Lists;

import java.lang.reflect.Field;
import java.util.List;

/**
 * Created by hww on 2018/7/29 下午3:37.
 */
public class WeatherList {

    List<Object> objects;

    public WeatherList() {
        objects = Lists.newArrayList();
    }

    public void get(Object object) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        Class<?> clazz = object.getClass();
        if (clazz.isAnnotationPresent(Entity.class)) {
            Field [] fields = clazz.getDeclaredFields();
            for (Field f : fields) {
                if (f.isAnnotationPresent(Resources.class)) {
                    Class<?> rainClass = Class.forName(f.getType().getName(), false, Thread.currentThread().getContextClassLoader());
                    f.set(object, rainClass.newInstance());
                    objects.add(object);
                }
            }
        }
    }

    public List<Object> returnList() {
        return objects;
    }

}
